import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import {beginAddRouter, routerChecked} from "@/router/routerSlider"
//iview 部分引入

import "@/mixins/iview.js"
import 'view-design/dist/styles/iview.css'
// 过滤器
import filters from "@/common/filters"
Vue.prototype.$filters = filters;
//全局工具
import tool from "@/common/tool"
Vue.prototype.$tool = tool;
Vue.prototype.unlocking = (name, value) => {
  let buttonControl = JSON.parse(tool.getStorage('buttonControl'))  
  if (name && value) {
    for (let item in buttonControl){
      if (item === name) {
        return buttonControl[name].includes(value)
      }
    }
  }
}

//全局常量
import formatter from "@/common/formatter"
Vue.prototype.$formatter = formatter;

router.beforeEach((to, from, next)=>{
    if(to.path == '/login')next();
    else if(tool.getStorage("X-Token") && tool.getStorage("rouList")){
      if(store.state.routerList){
        console.log(store.state.routerList,6666666,'routerList存在')
        routerChecked(to).then(res=>{
          next();
        }).catch(_=>next("/home"))

      }
      else{
        // console.log(7777777,'routerList不存在')
        beginAddRouter(to.path);
        next();
      }
    }
   else next('/login')
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
